Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = _default;

var _api = _interopRequireDefault(require("../../../../utils/api")), _echartsConfig = require("../../echarts-config");

function _interopRequireDefault(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

function _defineProperty(e, t, a) {
    return t in e ? Object.defineProperty(e, t, {
        value: a,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = a, e;
}

var ANALYZE = [ 0, 1, 2, 3, 4 ], ANALYZE_TYPE = [ "累计", "昨日", "本周", "本月", "上月" ], TREND = {
    newuser: "新增客户数",
    view: "浏览次数",
    transfer: "转发次数",
    fav: "保存次数",
    like: "点赞人数",
    contact: "沟通人数"
}, TREND_KEYS = Object.keys(TREND), TREND_TYPE = TREND_KEYS.map(function(e) {
    return TREND[e];
}), defaultComponent = {
    init: function() {}
}, overviewDatas = [ {
    id: "#analyze-statics",
    key: "analysis"
}, {
    id: "#analyze-funnel",
    key: "dealrate"
}, {
    id: "#chart-dom-clientfavrate",
    method: _echartsConfig.initPieChart,
    key: "clientfavrate"
}, {
    id: "#chart-dom-clientmutual",
    method: _echartsConfig.initBarChart,
    key: "clientmutual"
}, {
    id: "#chart-dom-recenttrends",
    method: _echartsConfig.initLineChart,
    key: "recenttrends"
}, {
    id: "#chart-dom-visitorfrom",
    method: _echartsConfig.initBarChart,
    key: "visitorfrom"
}, {
    id: "#chart-dom-area",
    method: _echartsConfig.initBarChart,
    key: "area"
}, {
    id: "#chart-dom-genderrate",
    method: _echartsConfig.initPieChart,
    key: "genderrate"
} ];

function _default() {
    var l;
    return {
        init: function(e) {
            (l = e).setData({
                trendIndex: 0,
                analyzeIndex: 0,
                ANALYZE_TYPE: ANALYZE_TYPE,
                TREND_TYPE: TREND_TYPE,
                analyze: {}
            });
        },
        onPullDownRefresh: function() {
            this.loadData(), wx.stopPullDownRefresh();
        },
        onReachBottom: function() {},
        chnageAnalyzeIndex: function(e) {
            l.setData({
                analyzeIndex: e
            }), this.loadData();
        },
        changeTrendIndex: function(e) {
            l.setData({
                trendIndex: e
            }), this.loadData();
        },
        loadData: function() {
            var t = this;
            overviewDatas.forEach(function(e) {
                wx.lazyFetch({
                    selector: e.id,
                    scope: l,
                    margins: {
                        bottom: 200
                    },
                    handler: function() {
                        return t.request(e.id, e.key, e.method);
                    }
                });
            });
        },
        request: function(a, n, i) {
            var r = this, e = l.data, t = e.trendIndex, o = e.analyzeIndex, d = e.isMasses, c = e.card, s = e.department, u = d ? "useroverview" : "overview";
            _api.default.minicard.analysis[u]({
                data: {
                    op: n,
                    guid: c.guid,
                    recenttype: TREND_KEYS[t],
                    cardid: c.cardid,
                    analysistime: ANALYZE[o],
                    catid: s.catid || ""
                }
            }).then(function(e) {
                var t = e.data;
                l.setData(_defineProperty({}, "analyze.".concat(n), t)), r.initCanvasData(a, n, i, t);
            });
        },
        initCanvasData: function(e, t, a, n) {
            e.includes("#chart-dom") && (l.selectComponent(e) || defaultComponent).init(a(n, t));
        }
    };
}